#ifndef COLOR_H
#define COLOR_H

#include <math.h>

/**
* This class declares the color of a pixel
*/
class Color
{
	
public:
	/**
	* The red, green and blue values
	*/
	float red,green,blue,alpha;
	
	Color(){}	
	Color(float r, float g, float b,float s): red(r), green(g), blue(b), alpha(s){}

	Color operator+(Vector& v){
		return Color(red += v.x, green += v.y, blue += v.z, alpha);
	}
	Color operator*(Vector& v){
		return Color(red *= v.x, green *= v.y, blue *= v.z, alpha);
	}
	/**
	* set the color values
	*/
	void setColor(float r, float g, float b,float s)
	{
		red = r;green = g;blue = b;alpha = s;
	}
	void setColor(Color c)
	{
		red = c.red;green = c.green;blue = c.blue;alpha = c.alpha;
	}
	float brightness()	{
		return (red + green + blue)/3;
	}
	void convert_To_Glut_Param(){
		red = red/255;green = green/255;blue = blue/255; alpha = alpha/255;
	}
	Color clip() {
		float alllight = red + green + blue;
		float excesslight = alllight - 3;
		if (excesslight > 0) {
			red = red + excesslight*(red/alllight);
			green = green + excesslight*(green/alllight);
			blue = blue + excesslight*(blue/alllight);
		}
		if (red > 1) {red = 1;}
		if (green > 1) {green = 1;}
		if (blue > 1) {blue = 1;}
		if (red < 0) {red = 0;}
		if (green < 0) {green = 0;}
		if (blue < 0) {blue = 0;}
		
		return Color (red, green, blue, alpha);
	}


	/**
	* Overload operators
	*/
	Color operator+(const Color& a){
		return Color(red+a.red,green+a.green,blue+a.blue,alpha+a.alpha);
	}
	Color operator+(const Vector& a){
		return Color(red+a.x,green+a.y,blue+a.z,alpha);
	}
	Color operator*(const Color& a){
		return Color(red*a.red,green*a.green,blue*a.blue,alpha*a.alpha);
	}
	Color operator*(const float& a){
		return Color(red*a,green*a,blue*a,alpha*a);
	}
	Color& operator= (const Color& c)
	{
		red = c.red; green = c.green;blue = c.blue;alpha = c.alpha;
		return *this;
	}

};


#endif